var data1=[
	['阿里云计算有限公司','746,106'],
	['华为软件技术有限公司','78,501'],
	['腾讯云计算（北京）有限责任公司','45,172'],
	['北京百度网讯科技有限公司','34,741'],
	['中国电信集团公司','25,701'],
	['广东一一五科技股份有限公司','6,398'],
	['上海有孚网络股份有限公司','5,354'],
	['北京优帆科技有限公司','1,442'],
	['广东睿江云计算股份有限公司','1,066'],
	['厦门鑫点击网络科技股份有限公司','852'],
	['北京小桔科技有限公司','747'],
	['广东金万邦科技投资有限公司','586'],
	['中国联合网络通信集团有限公司','551'],
	['北京京东叁佰陆拾度电子商务有限公司','345'],
	['成都西维数码科技有限公司','290']
]
var data2=[
	['中国电信集团公司',38],
	['中国联合网络通信集团有限公司',31],
	['阿里云计算有限公司',27],
	['华为软件技术有限公司',12],
	['北京百度网讯科技有限公司',11],
	['深圳市赛柏特通信技术有限公司',8],
	['腾讯云计算（北京）有限责任公司',8],
	['鹏博士电信传媒股份有限公司',6],
	['深圳前海小鸟云计算有限公司',6],
	['中国移动通信集团公司',6],
	['北京万国长安科技有限公司',6],
	['广州市明昕通信技术有限公司',6],
	['无锡华云数据技术服务有限公司',6],
	['北京金山云网络技术有限公司',6],
	['腾龙数据（北京）科技发展有限公司',6]
]
var data3=[
	['阿里云计算有限公司','3,366,278'],
	['腾讯云计算（北京）有限责任公司','390,543'],
	['中国电信集团公司','180,776'],
	['北京百度网讯科技有限公司','146,948'],
	['宁夏西云数据科技有限公司','131,103'],
	['华为软件技术有限公司','123,627'],
	['上海优刻得信息科技有限公司','65,539'],
	['中国联合网络通信集团有限公司','65,013'],
	['成都西维数码科技有限公司','41,220'],
	['北京新网数码信息技术有限公司','32,769'],
	['太平洋电信股份有限公司','23,791'],
	['中国移动通信集团公司','22,399'],
	['广东睿江云计算股份有限公司','9,559'],
	['广东金万邦科技投资有限公司','6,427'],
	['上海盛霄云计算技术有限公司','3,039']
]
listEvt(data1)
//右下tab切换
$(".YUNitem li").click(function(){
	n=$(this).index();
	$(this).addClass('active').siblings().removeClass('active')
	if(n==0){
		$(".YUNitem .tab_heard").html("")
	    $(".YUNitem .tab_heard").append("<tr>"+
	                "<th style='width:60px'>排名</th>"+
	                "<th>云企业名称</th>"+
	                "<th style='width:150px'>用户名总数</th>"+
	            +"</tr>")
		listEvt(data1)
	}else if(n==1){
		$(".YUNitem .tab_heard").html("")
	    $(".YUNitem .tab_heard").append("<tr>"+
	                "<th style='width:60px'>排名</th>"+
	                "<th>云企业名称</th>"+
	                "<th style='width:150px'>机房数</th>"+
	            +"</tr>")
		listEvt(data2)
	}else if(n==2){
		$(".YUNitem .tab_heard").html("")
	    $(".YUNitem .tab_heard").append("<tr>"+
	                "<th style='width:60px'>排名</th>"+
	                "<th>云企业名称</th>"+
	                "<th style='width:150px'>IP数</th>"+
	            +"</tr>")
		listEvt(data3)
	}
})

function listEvt(data){
	$("#ranklistRight1 .tab_content").html("")
        for(var i=0;i<data.length;i++){
            $("#ranklistRight1 .tab_content").append("<tr>"+
                    "<td style='width:60px'>"+(i+1)+"</td>"+
                    "<td title='"+data[i][0]+"'>"+data[i][0]+"</td>"+
                    "<td style='width:150px'>"+data[i][1]+"</td>"+
                +"</tr>")
        }
}



var geoCoordMap={}
var mapFeatures = echarts.getMap('china').geoJson.features;
mapFeatures.forEach(function(v) {
    // 地区名称
    var name = v.properties.name;
    // 地区经纬度
    geoCoordMap[name] = v.properties.cp;
});

var convertData = function (data) {
    var res = [];
    for (var i = 0; i < data.length; i++) {
        var geoCoord = geoCoordMap[data[i].name];
        if (geoCoord) {
            res.push({
                name: data[i].name,
                value: geoCoord.concat(data[i].value)
            });
        }
    }
    console.log(res)
    return res;
};

var mapData  = [
	{name:'北京',value:61},
	{name:'天津',value:3},
	{name:'河北',value:2},
	{name:'山西',value:3},
	{name:'内蒙古',value:1},
	{name:'辽宁',value:4},
	{name:'吉林',value:2},
	{name:'黑龙江',value:0},
	{name:'上海',value:44},
	{name:'江苏',value:8},
	{name:'浙江',value:10},
	{name:'安徽',value:7},
	{name:'福建',value:6},
	{name:'江西',value:2},
	{name:'山东',value:6},
	{name:'河南',value:9},
	{name:'湖北',value:7},
	{name:'湖南',value:2},
	{name:'广东',value:22},
	{name:'广西',value:0},
	{name:'海南',value:0},
	{name:'重庆',value:3},
	{name:'四川',value:7},
	{name:'贵州',value:5},
	{name:'云南',value:1},
	{name:'西藏',value:1},
	{name:'陕西',value:1},
	{name:'甘肃',value:2},
	{name:'青海',value:1},
	{name:'宁夏',value:2},
	{name:'新疆',value:1},
	{name:'台湾',value:0},
	{name:'香港',value:0},
	{name:'澳门',value:0},
];

function getOptionMap(data,max,type){
	var optionMap = {
			tooltip: {
				trigger: 'item',
				formatter:function(param){
					var province = param.name;
//					if(province !='香港' && province !='澳门' && province !='台湾'){
						return	'<div>'+param.name+'</div>' +
					        '<div>'+type+'数量：'+param.data.value[2]+'</div>';
					}  
//				}
			},
			geo: {
				show: true,
				zoom: 1.2,
				roam: false,
				map: 'china',
				itemStyle: {
					normal: {
						show: false,
						borderColor: '#285ac6',
						borderWidth: 1,
						areaColor: '#123082',
						shadowBlur: 3,
						shadowColor: '#081435',
						shadowOffsetX: -4,
						shadowOffsetY: 8
					},
					emphasis: {
						areaColor: '#fce24f',
						borderColor: '#fce24f'
					}
				}
			},
			series: [{
				type: 'map',
					zoom: 1.2,
					mapType: 'china',
					//		geoIndex: 0,
					roam: false,
					label: {
						normal: {
							show: false,
							textStyle: {
								color: '#fff'
							}
						},
						emphasis: {
							show: true,
							textStyle: {
								color: '#fff'
							}
						}
					},
					itemStyle: {
						normal: {
							show: false,
							borderColor: '#3770ea',
							borderWidth: 1,
							areaColor: '#0f2d87'
						},
						emphasis: {
							areaColor: '#2a56bd',
							borderColor: '#2a56bd',
							//				opacity: 0.8,
						}
					},
				data:convertData(data)
			},{
			 	name: 'Top 5',
	      type: 'effectScatter',
	      zlevel: 1,
	      coordinateSystem: 'geo',
	      symbolSize: function (val) {
	          return val[2]/max*20+5
	      },
	      showEffectOn: 'render',
	      rippleEffect: {
	          brushType: 'stroke'
	      },
	      hoverAnimation: true,
	      label: {
	          normal: {
	//            formatter: '{b}',
			        position: 'right',
			        show: false
	          }
	      },
	      itemStyle: {
	          normal: {
	              color: '#f4e925',
	              shadowBlur: 10,
	              shadowColor: '#333'
	          }
	      },
	//    data: convertData(mapData)
				data:convertData(data.sort(function(a,b){
					return b.value-a.value
				}).slice(0,5))
			},{
			 	name: 'Top 5',
	      type: 'scatter',
	      zlevel: 1,
	      coordinateSystem: 'geo',
	      symbolSize: function (val) {
	//        return val*4+8;
					return val[2]/max*20+5
	      },
	      showEffectOn: 'render',
	      rippleEffect: {
	          brushType: 'stroke'
	      },
	      hoverAnimation: true,
	      label: {
	          normal: {
	//            formatter: '{b}',
			        position: 'right',
			        show: false
	          }
	      },
	      itemStyle: {
	          normal: {
	              color: '#f4e925',
	              shadowBlur: 10,
	              shadowColor: '#333'
	          }
	      },
	//    data: convertData(mapData)
				data:convertData(data.sort(function (a, b) {
	          return b.value - a.value;
	      }).slice(5))
			}]
		};
	return optionMap;
}

var mapChart = echarts.init(document.getElementById('ec_map_nd'))
mapChart.setOption(getOptionMap(mapData,61,'企业'))

$(".mapChange").change(function(){
    var n = $(this).val();
    var mapData = null;
    var option = null;
    if(n =="企业"){
    	mapData = [
    		{name:'北京',value:61},
    		{name:'天津',value:3},
    		{name:'河北',value:2},
    		{name:'山西',value:3},
    		{name:'内蒙古',value:1},
    		{name:'辽宁',value:4},
    		{name:'吉林',value:2},
    		{name:'黑龙江',value:0},
    		{name:'上海',value:44},
    		{name:'江苏',value:8},
    		{name:'浙江',value:10},
    		{name:'安徽',value:7},
    		{name:'福建',value:6},
    		{name:'江西',value:2},
    		{name:'山东',value:6},
    		{name:'河南',value:9},
    		{name:'湖北',value:7},
    		{name:'湖南',value:2},
    		{name:'广东',value:22},
    		{name:'广西',value:0},
    		{name:'海南',value:0},
    		{name:'重庆',value:3},
    		{name:'四川',value:7},
    		{name:'贵州',value:5},
    		{name:'云南',value:1},
    		{name:'西藏',value:1},
    		{name:'陕西',value:1},
    		{name:'甘肃',value:2},
    		{name:'青海',value:1},
    		{name:'宁夏',value:2},
    		{name:'新疆',value:1},
    		{name:'台湾',value:0},
    		{name:'香港',value:0},
    		{name:'澳门',value:0},
    	];
    	option = getOptionMap(mapData,61,n);
    }else if(n =="机房"){
    	mapData = [
    		{name:'北京',value:162},
    		{name:'天津',value:14 },
    		{name:'河北',value:22 },
    		{name:'山西',value:8  },
    		{name:'内蒙古',value:11 },
    		{name:'辽宁',value:20 },
    		{name:'吉林',value:6  },
    		{name:'黑龙江',value:2  },
    		{name:'上海',value:115},
    		{name:'江苏',value:49 },
    		{name:'浙江',value:29 },
    		{name:'安徽',value:10 },
    		{name:'福建',value:21 },
    		{name:'江西',value:6  },
    		{name:'山东',value:23 },
    		{name:'河南',value:16 },
    		{name:'湖北',value:17 },
    		{name:'湖南',value:10 },
    		{name:'广东',value:110},
    		{name:'广西',value:5  },
    		{name:'海南',value:2  },
    		{name:'重庆',value:16 },
    		{name:'四川',value:26 },
    		{name:'贵州',value:9  },
    		{name:'云南',value:4  },
    		{name:'西藏',value:1  },
    		{name:'陕西',value:10 },
    		{name:'甘肃',value:2  },
    		{name:'青海',value:3  },
    		{name:'宁夏',value:10 },
    		{name:'新疆',value:1  },
    		{name:'台湾',value:0  },
    		{name:'香港',value:0  },
    		{name:'澳门',value:0  }
    	];
    	option = getOptionMap(mapData,162,n);
    }else if(n =="IP地址"){
    	mapData = [
    		{name:'北京',value:926569 },
    		{name:'天津',value:65468  },
    		{name:'河北',value:80752  },
    		{name:'山西',value:510    },
    		{name:'内蒙古',value:41325  },
    		{name:'辽宁',value:2420   },
    		{name:'吉林',value:942    },
    		{name:'黑龙江',value:519    },
    		{name:'上海',value:561753 },
    		{name:'江苏',value:30851  },
    		{name:'浙江',value:1366073},
    		{name:'安徽',value:805    },
    		{name:'福建',value:12561  },
    		{name:'江西',value:2561   },
    		{name:'山东',value:390347 },
    		{name:'河南',value:6687   },
    		{name:'湖北',value:3906   },
    		{name:'湖南',value:4299   },
    		{name:'广东',value:802142 },
    		{name:'广西',value:1104   },
    		{name:'海南',value:301    },
    		{name:'重庆',value:2905   },
    		{name:'四川',value:43726  },
    		{name:'贵州',value:8411   },
    		{name:'云南',value:2604   },
    		{name:'西藏',value:3      },
    		{name:'陕西',value:12175  },
    		{name:'甘肃',value:3335   },
    		{name:'青海',value:260    },
    		{name:'宁夏',value:66612  },
    		{name:'新疆',value:4101   },
    		{name:'台湾',value:0      },
    		{name:'香港',value:65820  },
    		{name:'澳门',value:0      },
    	];
    	option = getOptionMap(mapData,926569,n);
    }else if(n =="域名"){
    	mapData = [
    		{name:'北京',value:433722},
    		{name:'天津',value:22506 },
    		{name:'河北',value:58696 },
    		{name:'山西',value:21305 },
    		{name:'内蒙古',value:10493 },
    		{name:'辽宁',value:33462 },
    		{name:'吉林',value:14251 },
    		{name:'黑龙江',value:13467 },
    		{name:'上海',value:175853},
    		{name:'江苏',value:133094},
    		{name:'浙江',value:132181},
    		{name:'安徽',value:46117 },
    		{name:'福建',value:92279 },
    		{name:'江西',value:26388 },
    		{name:'山东',value:95740 },
    		{name:'河南',value:72230 },
    		{name:'湖北',value:65438 },
    		{name:'湖南',value:52435 },
    		{name:'广东',value:282931},
    		{name:'广西',value:19620 },
    		{name:'海南',value:8952  },
    		{name:'重庆',value:26659 },
    		{name:'四川',value:78279 },
    		{name:'贵州',value:17439 },
    		{name:'云南',value:18263 },
    		{name:'西藏',value:739   },
    		{name:'陕西',value:33622 },
    		{name:'甘肃',value:9410  },
    		{name:'青海',value:1681  },
    		{name:'宁夏',value:4042  },
    		{name:'新疆',value:6947  },
    		{name:'台湾',value:0     },
    		{name:'香港',value:0     },
    		{name:'澳门',value:0     },
    	];
    	option = getOptionMap(mapData,433722,n);
    }
//    optionMap.series[0].data = mapData;
	mapChart.setOption(option)
})

window.addEventListener("resize", function () {
    mapChart.resize();
});